package com.maimao.spider.controller;

import com.maimao.spider.mapper.BrandMapper;
import com.maimao.spider.mapper.CategoryMapper;
import com.maimao.spider.model.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author MaoLin Wang
 * @date 2020/11/25 11:16 上午
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandMapper brandMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @GetMapping("/add")
    @Transactional
    public String addBrandCategory(){
        List<Brand> brands = brandMapper.selectAll();
        List<Long> brandIds = brands.stream().map(Brand::getId).collect(Collectors.toList());
        brandMapper.insertCateBrandBatch(brandIds,114);
        return "ok";
    }
}
